package cate.game.play.util;

public class TimeCounter {

	public long startTime;

	public long lastMarkTime;

	public StringBuilder cache;

	public boolean silence;

	private void start(String reason) {
		startTime = System.nanoTime();
		lastMarkTime = startTime;
		cache = new StringBuilder();
		cache.append("\n");
		cache.append("【" + reason + "】开始了");
	}

	public TimeCounter(String reason) {
		start(reason);
	}

	public void silence(){
		silence = true;
	}

	public void mark(String reason) {
		cache.append("\n");
		cache.append("【" + reason + "】" + "阶段结束了");
		long now = System.nanoTime();
		long passTime = (now - lastMarkTime) / 1000;
		lastMarkTime = now;
		cache.append("耗时:【" + passTime + "】μs");
		cache.append("大约:【" + passTime / 1000 + "】ms");
	}

	public void stop() {
		long passTime = (System.nanoTime() - startTime) / 1000;
		cache.append("\n");
		cache.append("本次统计结束了");
		cache.append("耗时:【" + passTime + "】μs");
		cache.append("大约:【" + passTime / 1000 + "】ms");
		if(!silence){
			System.out.println(cache);
		}
	}


}
